package com.slipper.sfts.order.service;

import com.slipper.qmt.vo.*;
import com.slipper.sfts.order.service.support.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class DealerFactory {
    private static final Logger logger = LoggerFactory.getLogger(DealerFactory.class);

    private static final Map<Class<?>, IDealer<?>> dealerMap = new HashMap<Class<?>, IDealer<?>>() {{
        put(OrderVO.class, new OrderDealer());
        put(OrderResultVO.class, new OrderResultDealer());
        put(OrderErrorVO.class, new OrderErrorDealer());
        put(DealVO.class, new DealDealer());
        put(CancelVO.class, new CancelDealer());
        put(CancelErrorVO.class, new CancelErrorDealer());
    }};

    public static <T> void doDeal(T data) {
        if (data == null) {
            return;
        }

        @SuppressWarnings("unchecked")
        IDealer<T> dealer = (IDealer<T>) dealerMap.get(data.getClass());
        if (dealer == null) {
            logger.error("无[{}]数据类型的处理器！", data.getClass());
        } else {
            logger.info("[{}]消息处理：{}", dealer.getClass(), data);
            dealer.doDeal(data);
        }
    }
}
